<template>
	<view class="lot_info_box">
		<Tips/>
		<scroll-view scroll-y="true" class="lot_info_content" @scrolltolower="lower">
			<view class="join_card" v-for="item in helpRecordList" :key="item.id">
				<view class="join_avatar">
					<Avatar
						:fileName="item.user.user_avatar" 
						size="60rpx"/>
				</view>
				<view class="join_center">
					<view class="top text_ellipsis">
						{{item.user.nick_name}}
					</view>
					<view class="bottom text_ellipsis">
						{{deleteLot(item.createAt)}}
					</view>
				</view>
				<view v-if="item.isDiyShowState" class="join_info_state">
					{{item.isDiyShowState}}
				</view>
				<view v-else class="join_info_state">
					{{showState}}
				</view>
			</view>
			<view class="load_box">
				<uni-load-more :content-text="contentText" iconType="circle" :color="primary_hot_color" :status="loadingStatus" />
			</view>
			<view v-if="!helpRecordList.length">
				<MyNull img="nullEstate.png"/>
			</view>
		</scroll-view>
		<view v-if="isShowAddBtn" class="create_notice" @click="clickInviteHelp">
			<MyIcons size="130rpx" :src="joinSystemPath('addNotice.png')"/>
		</view>
	</view>
</template>

<script setup>
	import {ref} from 'vue'
	import {
		onShow,
		onLoad
	} from '@dcloudio/uni-app'
	
	import MyButton from '@/components/MyButton/MyButton.vue'
	import Tips from '@/components/Tips/Tips.vue'
	import MyNull from '@/components/MyNull/MyNull.vue'
	
	import {dynamicStyleStore} from '@/stores/dynamicStyle.js'
	import {
		DormitoryModel
	} from '@/service/model/dormitory.js'
	import {UserModel} from '@/service/model/user.js'
	
	import {
		joinSystemPath
	} from '@/utils/imgJoinName.js'
	import {
		deleteLot
	} from '@/utils/changeData.js'
	
	import {
		verifyIsLogin
	} from '@/hooks/verify.js'
	
	const dynamicStyle_store = dynamicStyleStore()
	const dormitoryModel = new DormitoryModel()
	const userModel = new UserModel()
	
	const {
		primary_hot_color,
		primary_light_color,
		primary_main_bgc,
		shallow_text_color,
		primary_text_color,
		primary_shallow_color
	} = dynamicStyle_store.dormitoryStyle
	
	const dormitoryAllId=uni.getStorageSync('homeData')
	
	const loadingStatus = ref('more')
	const contentText =ref({
		contentdown: '下滑加载更多',
		contentrefresh: '加载中',
		contentnomore: '没有更多助力记录了'
	})
	const isAllowGet=ref(true)
	const init=()=>{
		formData.value.page=0
		helpRecordList.value = []
		isAllowGet.value = true
	}
	
	const formData=ref({
		limit:10,
		page:0,
		orderBy:'createAt.desc',
	})
	
	const type=ref('')
	const showState = ref('助力成功')
	const isShowAddBtn = ref(true)
	
	const helpRecordList = ref([])
	const relation_id = ref('')
	const duty_id=ref('')
	const publicity_id=ref('')
	
	const getHelpList=async()=>{
		loadingStatus.value = 'loading'
		let data,success;
		switch(type.value){
			case "join_bgc_help":
				const {data:dataBgc,success:successBgc} = await dormitoryModel.getHelpJoinBgcList(formData.value,relation_id.value)
				data=dataBgc
				success=successBgc
				break;
			case "duty_clock_fill_help":
				const {data:dataClock,success:successClock} = await dormitoryModel.getDutyClockHelpList(formData.value,duty_id.value)
				data=dataClock
				success=successClock
				break
			case "publicity_all_success_user":
				const {data:publicityUsers,success:successPublicity} = await userModel.getPublicitySuccessUser(formData.value,publicity_id.value)
				data = publicityUsers
				success=successPublicity
				break
			case "out_publicity_balance":
				const {data:outPublicityBalance,success:successOutPublicity} = await userModel.getOutPublicityBalance(formData.value,publicity_id.value)
				data = outPublicityBalance
				success = successOutPublicity
				break
			default:
				uni.$emit('tips','error','页面错误')
		}
		
		if(success){
			helpRecordList.value = [...helpRecordList.value,...data]
			if(!data.length || data.length<formData.value.limit){
				isAllowGet.value = false
				loadingStatus.value = 'nomore'
			}else{
				loadingStatus.value = 'more'
			}
		}
	}
	
	const lower=()=>{
		if(!isAllowGet.value) return
		formData.value.page++
		getHelpList()
	}
	
	const clickInviteHelp=()=>{
		let url;
		switch(type.value){
			case "join_bgc_help":
				url = `/pages/Dormitory/InviteHelp/InviteHelp?relation_id=${dormitoryAllId.relation_id}&share=true&type=join_bgc_help`
				break;
			case "duty_clock_fill_help":
				url = `/pages/Dormitory/InviteHelp/InviteHelp?duty_id=${duty_id?.value}&share=true&type=duty_clock_fill_help`
				break
			case "publicity_all_success_user":
				url="/pages/User/Publicity/Publicity"
				break
			default:
				uni.$emit('tips','error','页面错误')
		}
		uni.navigateTo({
			url
		})
	}

	onLoad((opt)=>{
		init()
		const {type:_type} = opt
		console.log('dddd',opt)
		type.value = _type
		switch(_type){
			case "join_bgc_help":
				const {relation_id:_relation_id} = opt
				relation_id.value = _relation_id
				getHelpList()
				break;
			case "duty_clock_fill_help":
				const {duty_id:_duty_id} = opt
				duty_id.value = _duty_id
				getHelpList()
				break
			case "publicity_all_success_user":
				const {publicity_id:_publicity_id} = opt
				publicity_id.value = _publicity_id
				getHelpList()
				showState.value = '邀请成功'
				uni.setNavigationBarTitle({
					title:"成功邀请的用户"
				})
				contentText.value.contentnomore = "没有更多邀请记录了"
				isShowAddBtn.value = false
				break
			case "out_publicity_balance":
				const {publicity_id:_publicity_id_out} = opt
				publicity_id.value = _publicity_id_out
				getHelpList()
				uni.setNavigationBarTitle({
					title:"提现记录"
				})
				contentText.value.contentnomore = "没有更多提现记录了"
				isShowAddBtn.value = false
				break
			default:
				uni.$emit('tips','error','页面错误')
		}
		
	})
</script>

<style lang="less">
	.text_ellipsis{
		white-space:nowrap;
		text-overflow:ellipsis;
		overflow: hidden;
	}
	.lot_info_box{
		background-color: v-bind(primary_main_bgc);
		height: calc(100vh);
		padding: 20rpx;
		.lot_info_header{
			background-color: v-bind(primary_light_color);
			border-radius: 12rpx;
			padding: 20rpx;
			.item{
				text-align: center;
				width: 100%;
				margin: 10rpx 0;
			}
			.lot_title{
				color: v-bind(primary_text_color);
			}
			.join_nums{
				color: #FFFFFF;
			}
		}
		.lot_info_content{
			height: calc(95vh);
			.load_box{
				margin-bottom: 3%;
			}
			.join_card{
				margin-top: 20rpx;
				background-color: #FFFFFF;
				border-radius: 12rpx;
				padding: 10rpx 20rpx;
				display: flex;
				.join_avatar{
					width: 10%;
					display: flex;
					justify-content: center;
					align-items: center;
					margin-right: 10rpx;
				}
				.join_center{
					width: 60%;
					color: v-bind(primary_text_color);
					font-size: 30rpx;
					.bottom{
						color: v-bind(shallow_text_color);
						font-size: 25rpx;
					}
				}
				.join_info_state{
					width: 30%;
					display: flex;
					justify-content: center;
					align-items: center;
					color: v-bind(primary_hot_color);
					font-size: 30rpx;
				}
			}
		}
		.invite_joiner{
			margin: 0 !important;
			width: 100%;
			height: 100rpx;
			background-color: #FFFFFF !important;
			color: v-bind(primary_text_color);
			border: 0px solid #FFFFFF !important;
			font-size: 30rpx;
			display: flex;
			align-items: center;
			justify-content: center;
		}
		.create_notice{
			width: 130rpx;
			height: 130rpx;
			position: fixed;
			bottom: 100rpx;
			right: 50rpx;
			z-index: 10;
			background-color: v-bind(primary_hot_color);
			border-radius: 100rpx;
			display: flex;
			justify-content: center;
			align-items: center;
		}
		.create_notice:hover{
			background-color: v-bind(primary_shallow_color);
		}
	}
</style>
